<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="车牌号码" prop="plateNo">
        <el-input
          v-model="queryParams.plateNo"
          placeholder="请输入车牌号码"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡号/票号" prop="cardNo">
        <el-input
          v-model="queryParams.cardNo"
          placeholder="请输入卡号/票号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="筛选" prop="capFlag">
        <el-select
          v-model="queryParams.capFlag"
          placeholder="请选择筛选方式"
          clearable
          style="width: 240px">
          <el-option
            v-for="dict in dict.type.cap_flag"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="时间区间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          @change="handleTimestamp"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" fixed align="center" width="80">
        <template scope="scope">
          <span>{{(queryParams.pageIndex-1)*queryParams.pageSize+(scope.$index + 1)}} </span>
        </template>
      </el-table-column>
      <el-table-column label="车牌号码" align="center" prop="plateNo"/>
      <el-table-column label="车辆类型" align="center" prop="carType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_style" :value="scope.row.carStyle"/>
        </template>
      </el-table-column>
      <el-table-column label="图片" align="center" prop="imgInfo">
        <template slot-scope="scope" style="display: flex;">
          <el-image :src="scope.row.imgInfo" :preview-src-list="[scope.row.imgInfo]" style="width: 100px;height: 60px" />
        </template>
      </el-table-column>
      <el-table-column label="进场/出场" align="center" prop="cardState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cap_flag" :value="scope.row.capFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="地点" align="center" prop="capPlace"/>
      <el-table-column label="固定车类型" align="center" prop="carType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_type" :value="scope.row.carType"/>
        </template>
      </el-table-column>
      <el-table-column label="放行类型" align="center" prop="passType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pass_type" :value="scope.row.passType"/>
        </template>
      </el-table-column>
      <el-table-column label="放行说明" align="center" prop="passRemark" />
      <el-table-column label="进出场时间" align="center" prop="capTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.capTime,'{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageIndex"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>
<script>
  import { clientUrl } from "@/api/client";

  export default {
    name: "index",
    dicts: ['cap_flag', 'car_type','car_style','pass_type'],
    data(){
      return{
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 弹出层标题
        open: false,
        // 日期范围
        dateRange:[],
        //列表
        dataList:[],
        // 总条数
        total: 0,
        // 查询参数
        queryParams: {
          url:'/api/wec/GetCarInoutInfo',
          pageIndex: 1,
          pageSize: 10,
          serviceCode: 'getCarInoutInfo',
          plateNo:'',
          cardNo:'',
          startTime:undefined,
          endTime:undefined,
          capFlag:''
        },
      }
    },

    created() {
      this.getList();
    },

    methods:{
      /** 查询列表 */
      getList() {
        this.loading = true;
        clientUrl(this.queryParams).then(response => {
          let data = JSON.parse(response.data.data)
          this.dataList = data.detailList;
          this.total = parseInt(data.totalCount);
          this.loading = false;
        });
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageIndex = 1;
        this.getList();
      },

      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.queryParams.plateNo = '';
        this.queryParams.cardNo = '';
        this.queryParams.capFlag = '';
        this.dateRange = [];
        this.handleTimestamp();
        this.handleQuery();
      },

      handleTimestamp(){
        this.queryParams.startTime = undefined;
        this.queryParams.endTime = undefined;
        if(this.dateRange)this.queryParams.startTime = this.appendFix(this.dateRange[0],1);
        if(this.dateRange)this.queryParams.endTime =  this.appendFix(this.dateRange[1],2);
      }
    }
  }
</script>

<style scoped>

</style>
